﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace CxExtension
{
	public static class ListUtility
	{
		public static void AddRange<T>(this List<T> list,List<T> adds,int count)
		{
			int length = Math.Min(count,adds.Count);
			for(int i = 0;i < length;i++)
			{
				list.Add(adds[i]);
			}
		}
		/// <summary>
		/// 取得某个索引的值 如果往上越界就取最后的元素,往下越界就去最前的元素
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="list"></param>
		/// <param name="indx"></param>
		/// <returns></returns>
		public static T Get<T>(this List<T> list,int indx)
		{
			int count = list.Count;
			if(count > 0)
			{
				if(indx >= count)
				{
					indx = count - 1;
					Debug.LogWarningFormat("数组越界了!count ={0},indx = {1}",count,indx);
				}
				return list[indx];
			}
			else
			{
				Debug.LogWarningFormat("一个元素都没有 还要去索引{0}的值",indx);
				return default(T);
			}
		}
	}
}
